package our_tests;

import static org.junit.Assert.*;

import java.io.FileNotFoundException;
import java.io.IOException;

import logic.huffman.HuffmanTree;

import org.junit.Test;

import datamodel.RGB;
import datamodel.huffman.tree.Tree;

/**
 * Tests HuffmanTree
 * @author Magnus Brand
 *
 */
public class HuffmannTreeTest {

	@Test
	public void testGetHuffmanTree() {
		// build the correct tree and compare (The brightness values are probably wrong, but this is what the
		// ImageIterator shows during debugging. Not my fault...
		Tree ht = new Tree();
		ht.setCurrentNode(new Tree.Node(null)); // 64
		
		ht.setLeftNode(new Tree.Node(null)); // 36
		ht.setRightNode(new Tree.Node(new RGB(0,255,0,255))); // 28 - green
		ht.moveToLeftNode();
		
		ht.setLeftNode(new Tree.Node(null)); // 21
		ht.setRightNode(new Tree.Node(null)); // 15
		ht.moveToRightNode();
		ht.setLeftNode(new Tree.Node(new RGB(255, 0, 0,255))); // 8 - red
		ht.setRightNode(new Tree.Node(new RGB(0,255,255,255))); // 7 - cyan
		
		ht.moveToParentNode();
		ht.moveToLeftNode();
		
		ht.setLeftNode(new Tree.Node(new RGB(255,0,255,255))); // 12 - purple
		ht.setRightNode(new Tree.Node(null)); // 9
		
		ht.moveToRightNode();
		ht.setLeftNode(new Tree.Node(new RGB(0,0,0,255))); // 6 - black
		ht.setRightNode(new Tree.Node(null)); // 3
		
		ht.moveToRightNode();
		ht.setLeftNode(new Tree.Node(new RGB(0,0,255,255))); // 2 - blue
		ht.setRightNode(new Tree.Node(new RGB(255,255,0,255))); // 1 - yellow
		
		
		
		
		try {
			Tree actualHT = HuffmanTree.getHuffmanTree("test2.png");
			assertEquals(ht, actualHT);
		} catch (FileNotFoundException e) {
			System.err.println("\"test2.png\" not found: ");
			e.printStackTrace();
		} catch (IOException e) {
			System.err.println("some IO-related error occured: ");
			e.printStackTrace();
		}
		
	}

}
